package com.itheima.crm.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.itheima.crm.pojo.RiZhi;
import com.itheima.crm.service.RiZhiService;

/**
 * 客户管理
 * 
 * @author lx
 *
 */
@Controller
public class MainController {

	@Autowired
	private RiZhiService rizhiService;
	
	public RiZhiService getRizhiService() {
		return rizhiService;
	}

	public void setRizhiService(RiZhiService rizhiService) {
		this.rizhiService = rizhiService;
	}

	@RequestMapping(value = "/Main")
	public ModelAndView Main(Model model,HttpServletRequest request) {
		 String zhiwei=(String) request.getSession().getAttribute("zhiwei");
		 if(!zhiwei.equals("3")) {

		ModelAndView b = new ModelAndView();
		b.setViewName("Main");
		RiZhi a=new RiZhi();
		
		a.setYgid((Integer)request.getSession().getAttribute("ygid"));
		a.setYgname((String)request.getSession().getAttribute("ygname"));
		a.setInsertdate(new Date());
		System.out.println(a.getInsertdate());
		a.setDetial("登录员工系统");
		rizhiService.insertApplication(a);
		

		return b;
		 }else {
			 
			 ModelAndView b = new ModelAndView();
				b.setViewName("GuanLiMain"); 
				RiZhi a=new RiZhi();
				
				a.setYgid((Integer)request.getSession().getAttribute("ygid"));
				a.setYgname((String)request.getSession().getAttribute("ygname"));
				a.setInsertdate(new Date());
				System.out.println(a.getInsertdate());
				a.setDetial("登录管理员系统");
				rizhiService.insertApplication(a);
			 return b;
		 }
		

	}
		
	
	

	
}
